import org.junit.Test;

import java.io.File;
import java.util.Arrays;

public class FileTest {
    public static void main(String[] args) {
        File codeDir = new File("D:\\Code\\study");
        listFileName(codeDir);
    }

    public static void listFileName(File file) {
        if (null == file || !file.exists()) {
            return;
        }

        File[] subFiles = file.listFiles((File f, String name) -> !file.isHidden());
        if (null == subFiles || subFiles.length < 1) {
            return;
        }

        for (File f : subFiles) {
            if (f.isDirectory()) {
                listFileName(f);
            } else {
                System.out.println(f.getName());
            }
        }
    }

    @Test
    public void test1() {
        File file = new File("config");
        System.out.println(file.isDirectory());
        System.out.println(Arrays.toString(file.list()));

    }

    @Test
    public void test2() throws RuntimeException {
        File pictures = new File("D:\\pictures");
        if (!(pictures.exists() && pictures.isDirectory())) {
            throw new RuntimeException("文件夹不存在或");
        }

        String[] picture = pictures.list((File file, String name) -> name.endsWith(".jpg"));
        if (null == picture || picture.length < 1) {
            throw new RuntimeException("图片读取失败");
        }

        for (String s : picture) {
            if (s.endsWith(".jpg")) {
                System.out.println(s);
            }
        }
    }
}
